#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <math.h>

//海拔计算
long  BMP180_Calc_HB(long Pa)
{
	return 44330 * (1 - pow( Pa/ 101325.0f, 1.0f / 5.255f));
}

int main(int argc, char **argv)
{
	int fd=0;
	int ret=0;
	long data[2]={0};
	long hight=0;

	if(argc !=2)
	{
		printf("Usage error %s\r\n",argv[0]);
		return -1;
	}

	fd = open(argv[1],O_RDWR);
	if(fd <0)
	{
		printf("open file:%s error\r\n",argv[1]);
		return -1;
	}

	while(1)
	{
		ret = read(fd, data, sizeof(data));
		if(ret <0)
		{
			printf("read error! ret:%d\r\n",ret);
			return -1;
		}
		hight= BMP180_Calc_HB(data[1]);
		printf("temperature:%d pressure:%d hight:%d\r\n",data[0], data[1] ,hight);
		
		sleep(1);
	}
	
	close(fd);

	return 0;
}


